/**
 * Curso B�sico de desarrollo de Juegos en Java - Invaders
 * 
 * (c) 2004 Planetalia S.L. - Todos los derechos reservados. Prohibida su reproducci�n
 * 
 * http://www.planetalia.com
 * 
 */
package co.edu.usbcali.raju.core.graphics;

import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;

import co.edu.usbcali.raju.core.AbstractViewPanel;
import co.edu.usbcali.raju.games.chess.gui.BoardPanel;

public class Actor {
	protected int x,y;
	protected int width, height;
	protected String[] spriteNames;
	protected int currentFrame;
	protected int frameSpeed;
	protected int t;
	protected AbstractViewPanel stage;
	protected SpriteCache spriteCache;
	protected boolean markedForRemoval;
	
	public Actor(AbstractViewPanel panel) {
		this.stage = panel;
		spriteCache = stage.getSpriteCache();
		currentFrame = 0;
		frameSpeed = 1;
		t=0;
	}
	
	public void remove() {
		markedForRemoval = true;
	}
	
	public boolean isMarkedForRemoval() {
		return markedForRemoval;
	}
	
	public void paint(Graphics g){
		g.drawImage( spriteCache.getSprite(spriteNames[currentFrame]), x,y,BoardPanel.CELL_WIDTH,BoardPanel.CELL_HEIGHT, stage );
	}
	
	public int getX()  { return x; }
	public void setX(int i) {	x = i; }

	public int getY() {	return y; }
	public void setY(int i) { y = i; }
	
	public int getFrameSpeed() {return frameSpeed;	}
	public void setFrameSpeed(int i) {frameSpeed = i;	}
	
	
	public void setSpriteNames(String[] names) { 
		spriteNames = names;
		height = 0;
		width = 0;
		for (int i = 0; i < names.length; i++ ) {
  		BufferedImage image = spriteCache.getSprite(spriteNames[i]);
	  	height = Math.max(height,image.getHeight());
		  width = Math.max(width,image.getWidth());
		}
	}			
	
	public int getHeight() { return height; }
	public int getWidth() {	return width;	}
	public void setHeight(int i) {height = i;	}
	public void setWidth(int i) {	width = i;	}

	public void act() {
		t++;
		if (t % frameSpeed == 0){
			t=0;
  		currentFrame = (currentFrame + 1) % spriteNames.length;
		}
	}
	
	public Rectangle getBounds() {
		return new Rectangle(x,y,width,height);
	}
	
	public void collision(Actor a){
		
	}
}
